<?php
if (!defined("KU6_PROJECT")) {
	die("hacking attack");
}
/**
 * 错误码 
 */
#@todo
class Ku6ErrorCode
{
    /*
     * 错误号
     */
    const API_EC_SUCCESS = 0;
    const API_EC_UNKNOWN = - 10001;
    const API_EC_SERVICE = - 10002;
    const API_EC_TIMEOUT = - 10003;
    const API_EC_METHOD = - 10004;
    const API_EC_PARAM = - 10005;
    const API_EC_TOO_MANY_CALLS = - 10006;
    CONST API_EC_CONNECT_DB = -10007;

    /*
    const API_EC_SUCCESS = 0;
    const API_EC_UNKNOWN = 101;
    const API_EC_SERVICE = 101;
    const API_EC_TIMEOUT = 101;
    const API_EC_METHOD = 101;
    const API_EC_PARAM = 101;
    const API_EC_TOO_MANY_CALLS = 101;
    const API_EC_CONNECT_DB = 101;
     */
   
    /*
     * 错误号与错误字符串映射
     */
    protected static $errorCode = array(
        self::API_EC_SUCCESS => 'success', 
        self::API_EC_UNKNOWN => 'An unknown error occurred.', 
        self::API_EC_SERVICE => 'Service temporarily unavailable.', 
        self::API_EC_TIMEOUT => 'TIMEOUT.', 
        self::API_EC_METHOD => 'Invalid Method Name', 
        self::API_EC_PARAM => 'Invalid Parameter.', 
        self::API_EC_TOO_MANY_CALLS => 'Application request limit reached.', 
        self::API_EC_CONNECT_DB => "can't connect to db host."
    );
    /*
     * 通过错误号构造错误返回
     * @param int $code 错误号
     * @param string $msg 错误信息
     * @return array
     */
    static function populateError ($code, $msg)
    {
        return array(
            "errNo" => $code, 
            "errMsg" => $msg
        );
    }
    
    static function getErrMsg($code=-1)
    {
        if ($code!=-1) {
        	return self::$errorCode[$code];
        }
        return self::$errorCode;
    }
}
